# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=tacacs+ng
pkgver=0_git20230214
_gitrev=184d084e84766e33f63e84c99d6d16cabae87258
pkgrel=1
pkgdesc="TACACS+ NG authentication daemon"
url="https://www.pro-bono-publico.de/projects/tac_plus-ng.html"
arch="all"
license="MIT AND BSD-2-Clause"
makedepends="
	c-ares-dev
	libretls-dev
	pcre2-dev
	perl
	radcli-dev
	linux-headers
	"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-openrc
	$pkgname-radius
	$pkgname-perl-ldap::noarch
	$pkgname-perl::noarch
	"
install="$pkgname.pre-install"
source="https://github.com/MarcJHuber/event-driven-servers/archive/$_gitrev/event-driven-servers-$_gitrev.tar.gz
	fix-include-poll.h.patch
	libmavis-soname.patch
	kill-rpath.patch
	tac_plus-ng.initd
	tac_plus-ng.confd
	"
builddir="$srcdir/event-driven-servers-$_gitrev"
options="!check"  # no tests provided

prepare() {
	default_prepare

	sed -i 's|^#!../../../sbin/tac_plus-ng|#!/usr/sbin/tac_plus-ng|' \
		tac_plus-ng/sample/*.cfg
}

build() {
	./configure \
		--prefix=/usr \
		--etcdir=/etc \
		--docdir=/usr/share/doc/$pkgname \
		--with-ares \
		--without-curl \
		--with-epoll \
		--without-execinfo \
		--without-freeradius \
		--with-ipc \
		--without-lwres \
		--without-pam \
		--without-pcre \
		--with-pcre2 \
		--with-radcli \
		--with-sctp \
		--without-ssl \
		--with-tls \
		tac_plus-ng
	make -j1
}

package() {
	make install -j1 INSTALLROOT="$pkgdir"

	cd "$pkgdir"

	# Remove messy sample config.
	rm -rf etc/mavis

	# Remove HTML and PDF docs.
	find usr/share/doc/$pkgname/ -type f ! -name '*.txt' -delete

	# XXX: We don't package perl-authen-opie (yet).
	rm usr/lib/mavis/mavis_tacplus_opie.pl

	# Install sample configs.
	install -D -m644 "$builddir"/tac_plus-ng/sample/*.cfg \
		-t "$pkgdir"/usr/share/doc/$pkgname/samples/

	install -D -m755 "$srcdir"/tac_plus-ng.initd "$pkgdir"/etc/init.d/tac_plus-ng
	install -D -m644 "$srcdir"/tac_plus-ng.confd "$pkgdir"/etc/conf.d/tac_plus-ng
}

radius() {
	pkgdesc="MAVIS RADIUS backend based on radcli for TACACS+ NG"

	amove usr/sbin/radmavis
}

ldap() {
	pkgdesc="MAVIS LDAP backend for TACACS+ NG"
	depends="$pkgname-perl=$pkgver-r$pkgrel perl-ldap"

	amove usr/lib/mavis/extra
	amove usr/lib/mavis/mavis_*ldap*.pl
}

perl() {
	pkgdesc="MAVIS backends written in Perl for TACACS+ NG"
	depends="$pkgname=$pkgver-r$pkgrel perl"

	amove usr/lib/mavis/*.pm
	amove usr/lib/mavis/*.pl
}

sha512sums="
262459227b462ccada2532ead461f339320b93473a9fbb4afc1c0789d0f3b17b4ceba3cdc34b2b8c981889218c0f11803de2c7b9a47af85dd96b85843996c447  event-driven-servers-184d084e84766e33f63e84c99d6d16cabae87258.tar.gz
25cc6877536a59496c71c96f7a5c2b2f17f3fe2f7d823146e334f5f85f9933911eab051678982667bb4aef38b2d125fe152ad310e441c1b9d2cd7c62cc142923  fix-include-poll.h.patch
da0013214d46b551e68677e7ee1f24909223e2cbb80b015aa5a078800b42d147f1a5719038d46ebf777cb5d6a8270c648fa9f71d85081d0806a188de83a6bba7  libmavis-soname.patch
ad6f09f524a1eb5e3402ea1f19c7a2fb1b7f4f45ea08fdd955aa340966aa1082745e05665fe1f89103f303ab89de24369b55a65b0e2f2774194f6d30175ef026  kill-rpath.patch
d0e7dcdfac8cd1e0912de05d502758099587db06244b5ba62583d0b90d274686b1dc0784fde8246145414d276cf99273afcc501350cbacce6eed9fde7fbdb8ba  tac_plus-ng.initd
7cdd9b41b9224cecc46915cdc6100732381aacd39a624e01e4941321d929af0ae6f9c33b6f6842b07292fed558bfd7c5fad12d818dc73dca3582dd6089f01103  tac_plus-ng.confd
"
